$(function() {
	var username = localStorage.getItem("dingcan_username");
	$(".LeftNav").empty();
	if(username == null || username == "" || username == "undefined") {
		$(".LeftNav").html('<a href="register.html">注册</a>/<a href="login.html">登录</a><a href="#">QQ客服</a><a href="#">微信客服</a><a href="#">手机客户端</a>');
	} else {
		$(".LeftNav").html('欢迎 <b>'+username+'</b> <a href="index.html" onclick="quit()">退出登陆</a><a href="#">QQ客服</a><a href="#">微信客服</a><a href="#">手机客户端</a>');
		$(".user_name").html(username);
	}
	
	changeCart();

});

function changeCart() {
	$.ajax({
		cache:true,
		type:"GET",
		url:"/dingcan/dingcan/listCard.do",
		async:true,
		success:function(data) {
			var card = JSON.parse(data).data;
			if(card == null) {
				var foodNum = 0;
				var html = '<a href="/dingcan/dingcan/userCenterApp.do">用户中心</a> <a href="user_orderlist.html" target="_blank" title="我的订单">我的订单</a> <a href="cart.html">购物车（'+ foodNum +'）</a> <a href="user_favorites.html" target="_blank" title="我的收藏">我的收藏</a>';
				$(".RightNav").html(html);
				 
			} else {
				var foodNum = card.foods.length;
				var html = '<a href="/dingcan/dingcan/userCenterApp.do">用户中心</a> <a href="user_orderlist.html" target="_blank" title="我的订单">我的订单</a> <a href="cart.html">购物车（'+ foodNum +'）</a> <a href="user_favorites.html" target="_blank" title="我的收藏">我的收藏</a>';
				$(".RightNav").html(html);
			}
			
		}
	});
}

function quit() {
	localStorage.removeItem("dingcan_username");
}


